/**
 * zmn产品模块-产品列表
 * @author tanghongjun
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-189'
    });
    laypage.render(zmnPage.laypageOptions(json));

    let ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.groupId);
    });

    //查询条件重置
    form.on('submit(zmn-form-reset)', function (obj) {
        form.val("zmn-query-filter", {
            "nameOrGroupId": ""
            ,"plat": ""
            ,"module": ''
            ,"status": ""
        });
        return false;
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event != "start" && obj.event != "stop") {
            return;
        }
        if (ids.length === 0) {
            return layer.alert("请选择至少1个模板组！");
        }
        zmnPage.layStartStop(obj, "/msg/temp/group/updateStatus.action", ids.join(","));
    });

    // 修改排序
    table.on("edit(zmn-table)", function (obj) {
        zmnPage.laySort(obj, "/msg/temp/group/updateSort.action", obj.data.groupId);
    });

    //对外暴露的接口
    exports('msg_template_group_list', {});
});

/**
 * 描述: 新增模板组
 **/
function addTempGroup(){
    zmnLayUtil.openIframeCustom(layer, "/msg/temp/group/addEditView.action", {title: "新增模板组", shade: 0.8, area:["900px", "80%"]});
}

/**
 * 描述: 新增模板组
 **/
function editTempGroup(groupId){
    zmnLayUtil.openIframeCustom(layer, "/msg/temp/group/addEditView.action?groupId="+groupId, {title: "修改模板组", shade: 0.8, area:["900px", "80%"]});
}

